<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
	function sosuo() {
		var lpath = location.pathname;
		$("#soform").attr("action", lpath + "?pageNo=" + 1);

		$("#soform").submit();
	}
	var exceldialog=null;
	function uploaddialog(){
		//var param ={id:newproid};
		exceldialog = art.dialog.uploadFile("上传logo",{callback:"uploadcallback",userpath:"admin",extensions:"gif,jpg,png,jepg"});
	}

	function uploadcallback(response){
		//alert(response.url);
		//alert(params.id);
		exceldialog.close();
		$("#logoUrl").attr("href",response.url);
		$("#logoUrl").text(response.url);
		$("[name='logo']").val(response.url)
	}
</script>
</head>

<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading">
			<button style="float: right" type="button" onclick="addrecommendCompany()" class="btn btn-info">
				<span class="glyphicon glyphicon-plus"></span>
				&nbsp;新增推荐
			</button>
			<form id="soform" method="post">
				<input type="hidden" name="so_companyId" value="${so_companyId!}">
				<table>
					<tr>
						<td class="w80" style="padding-top: 5px">
							<label for="companyname" class="center-block">公司名称：</label>
						</td>
						<td class="w150 ">
							<input type="text" class="form-control" name="so_search" value="${so_search!}" id="so_search" placeholder="请输入公司名称" data-options="">
						</td>
						<td class="w80" style="padding-top: 5px; padding-left: 10px">
							<label for="companyname" class="center-block">推荐类型：</label>
						</td>
						<td class="w120 ">
							<select class="form-control" name="so_upToIndex">
							    <option value="" [#if !so_upToIndex?? || so_upToIndex=='']selected="selected"[/#if]>全部</option>
								<option value="0" [#if so_upToIndex?? && so_upToIndex=='0']selected="selected"[/#if]>不推荐</option>
								<option value="1" [#if so_upToIndex?? && so_upToIndex=='1']selected="selected"[/#if]>推荐</option>
							</select>
						</td>
						<td style="padding-left: 10px">
							<div class="input-group">
								<span class="input-group-btn">
									<button class="btn btn-default" type="button" onclick="sosuo()">搜索</button>
								</span>
							</div>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
			<thead>
				<tr>
					<th width="15%">序号</th>
					<th width="20%">公司名称</th>
					<th width="15%">链接地址</th>
					<th width="15%">企业logo</th>
					<th width="10%">排序号</th>
					<th width="10%">是否推荐到首页</th>
					<th width="15%">操作</th>
				</tr>
			</thead>
			[#list pagination.list as reCompany]
			<tr>
				<td align="center">${reCompany_index + 1}</td>
				<td align="center">${reCompany.companyName!}</td>
				<td align="center"><a target="_blank" href="${reCompany.urlPath!}">${reCompany.urlPath!}</a></td>
				<td align="center"><a target="_blank" href="${reCompany.logo!}">${reCompany.logo!}</a></td>
				<td align="center">${reCompany.seq!}</td>
				<td align="center">[#if reCompany.upToIndex==1]推荐[#else]不推荐[/#if]</td>
				<td align="center">
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="edit('${reCompany.id!}')">编辑</button>
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="deleteCP('${reCompany.id!}')">删除</button>
				</td>
			</tr>
			[/#list]
		</table>
		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>
	
	<!-- 添加编辑  -->
	<div id="editoraddView" style="width: 600px; height: 300px; display: none;">
		<form id="editoraddform" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="id" id="recom_comId">
			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">公司名称</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" placeholder="请输入公司名称" min="1" required="required" name="companyName" id="addtitle">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">链接地址</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" placeholder="请输入链接地址" min="1" required="required" name="urlPath" id="addtitle">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">排序号</label>
				<div class="col-sm-8">
					<input type="number" class="form-control" placeholder="请输入排序号" min="1" required="required" name="seq" id="addtitle" value="1">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">是否推荐</label>
				<div class="col-sm-8">
					<select name="upToIndex" class="form-control">
							<option value="0">否</option>
							<option value="1">是</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">企业logo</label>
				<div class="col-sm-8">
					<button onclick="uploaddialog()" type="button" class="btn btn-default">上传logo</button>
				</div>
				<div style="display: inline-block;float: left;margin-left: 120px;margin-top: 15px;">
					<a target="_blank" id="logoUrl" href=""></a>
				</div>
				<input name="logo" type="hidden" value="">
			</div>
			<div class="form-group" style="margin-top: 10px;">
				<div class="col-sm-offset-2 col-sm-10">
					<input id="addoreditsub" type="button" onclick="subForm()"  class="btn btn-default" value="提交" />
				</div>
			</div>
		</form>
	</div>
	
</body>
</html>
<script type="text/javascript">
	
	//打开编辑窗口
	function edit(id) {
		clearForm();
		 $.ajax({
				url : '/recommendCompany/queryEditRC.do',
				type : 'post',
				dataType : 'json',
				data :{id:id},
				beforeSend : function() {
					art.dialog.tips("请求中...");
				},
				success : function(data) {
					if (data.success) {
						$("#recom_comId").val(data.obj.id)
						$("input[name='logo']").val(data.obj.logo);
						$("#logoUrl").attr("href",data.obj.logo);
						$("#logoUrl").text(data.obj.logo);
						$("input[name='companyName']").val(data.obj.companyName);
						$("input[name='urlPath']").val(data.obj.urlPath);
						$("input[name='seq']").val(data.obj.seq);
						$("select[name='upToIndex']").children("option").each(function(){
							if($(this).val()==data.obj.upToIndex){
								$(this).attr("selected","selected")
							}
						})
					} else {
						error_msg(data.msg, function() {
							location.reload();
						});
					}
				}
			});
		dialog = art.dialog({
			title : "编辑",
			lock : true,
			content : document.getElementById('editoraddView')
		});
	}
	//打开新增窗口
	function addrecommendCompany(){
		clearForm();
		dialog = art.dialog({
			title : "新增",
			lock : true,
			content : document.getElementById('editoraddView')
		});
	}
	function validate(){
		 var isVal=true;
		 if($("[name='logo']").val()==''){
			 alert("logo必须上传")
			 isVal =false;
		 }
		 if($("[name='companyName']").val()==''){
			 alert("公司名称必须填写")
			 isVal =false;
		 }
		 if($("[name='urlPath']").val()==''){
			 alert("链接必须填写")
			 isVal =false;
		 }
		 return isVal;
	}
	function subForm(){
		 if(validate()){
			 if(confirm("确认提交吗")){
				 $.ajax({
						url : '/recommendCompany/editOradd.do',
						type : 'post',
						dataType : 'json',
						data :$("#editoraddform").serialize(),
						beforeSend : function() {
							art.dialog.tips("提交中...");
						},
						success : function(data) {
							if (data.success) {
								location.reload();
							} else {
								error_msg(data.msg, function() {
									location.reload();
								});
							}
						}
					});
			 }
		 }
	}
	function clearForm(){
		$("#recom_comId").val('');
		$("input[name='logo']").val('');
		$("input[name='companyName']").val('');
		$("input[name='urlPath']").val('');
		$("input[name='seq']").val('1');
		$("input[name='upToIndex']").each(function(){
			$(this).removeAttr("selected");
		})
	}
	function deleteCP(id){
		if(confirm("确认删除吗")){
			 $.ajax({
					url : '/recommendCompany/deleteCP.do',
					type : 'post',
					dataType : 'json',
					data :{id:id},
					beforeSend : function() {
						art.dialog.tips("提交中...");
					},
					success : function(data) {
						if (data.success) {
							location.reload();
						} else {
							error_msg(data.msg, function() {
								location.reload();
							});
						}
					}
				});
		}
	}
</script>